//
// Created by aaa on 2025/7/10.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 1e3 + 10;

int a[N][N];
int dp[N][N];
int n;

int dfs(int x,int y){
    if(dp[x][y] != 0) return dp[x][y];

    if(x == n) dp[x][y] = a[x][y];
    else dp[x][y] = a[x][y] + max(dfs(x+1,y),dfs(x+1,y+1));
    return dp[x][y];
}

//记忆化搜索 数字三角形
//5
//7
//3 8
//8 1 0
//2 7 4 4
//4 5 2 6 5
int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= i;j++) cin >> a[i][j];
    }

    dfs(1,1);
    cout << dp[1][1];

    return 0;
}